class BaseModel {
  constructor({ errno, data, message }) {
    this.errno = errno;
    if (data) {
      this.data = data;
    }
    if (message) {
      this.message = message;
    }
  }
}

class SuccessModel extends BaseModel {
  constructor(data = {}) {
    super({
      errno: 0,
      data,
    });
  }
}

class ErrorModel extends BaseModel {
  static registerUsernameExistInfo() {
    return new ErrorModel({
      errno: 10001,
      message: "用户名已存在",
    });
  }

  static registerFailInfo() {
    return new ErrorModel({
      errno: 10002,
      message: "注册失败，请重试",
    });
  }

  static registerUserNameNotExistInfo() {
    return new ErrorModel({
      errno: 10003,
      message: "用户名不存在，可以注册",
    });
  }

  static loginFailInfo() {
    return new ErrorModel({
      errno: 10004,
      message: "登录失败，用户名或密码错误",
    });
  }

  static loginCheckFailInfo() {
    return new ErrorModel({
      errno: 10005,
      message: "您尚未登录",
    });
  }

  static changePasswordFailInfo() {
    return new ErrorModel({
      errno: 10006,
      message: "修改密码失败，请重试",
    });
  }

  static uploadFileSizeFailInfo() {
    return new ErrorModel({
      errno: 10007,
      message: "上传文件尺寸过大",
    });
  }

  static changeInfoFailInfo() {
    return new ErrorModel({
      errno: 10008,
      message: "修改基本信息失败",
    });
  }

  static jsonSchemaFailInfo() {
    return new ErrorModel({
      errno: 10009,
      message: "数据格式校验失败",
    });
  }

  static deleteUserFailInfo() {
    return new ErrorModel({
      errno: 10010,
      message: "删除用户失败",
    });
  }

  static addFollowerFailInfo() {
    return new ErrorModel({
      errno: 10011,
      message: "添加关注失败",
    });
  }

  static deleteFollowerFailInfo() {
    return new ErrorModel({
      errno: 10012,
      message: "取消关注失败",
    });
  }

  static createBlogFailInfo() {
    return new ErrorModel({
      errno: 11001,
      message: "创建微博失败，请重试",
    });
  }

  static deleteBlogFailInfo() {
    return new ErrorModel({
      errno: 11002,
      message: "删除微博失败，请重试",
    });
  }

  static unNormalFailInfo() {
    return new ErrorModel({
      errno: 11999,
      message: "网络异常，请联系管理员",
    })
  }

  constructor({ errno, message }) {
    super({
      errno,
      message,
    });
  }
}

module.exports = {
  SuccessModel,
  ErrorModel,
};
